//
//  Pet_PublishStoryViewController.swift
//  PetApp
//
//  Created by mac on 2023/9/20.
//  Copyright © 2023 Pet_. All rights reserved.
//

import UIKit

class Pet_PublishStoryViewController: BasicViewController {

    let titL = UILabel.initV(UIFont.setTypeFace(25.Fit,type: .bold), text: "to tell us about your pet sotyr", textColor:.black)
    private lazy var descView: Custom_TextView = {
        let view = Custom_TextView()
        view.backgroundColor = UIColor.white
        view.textContainerInset = UIEdgeInsets(top: 10.Fit, left: 10.Fit, bottom: 10.Fit, right: 10.Fit)
        view.tintColor = .black
        view.textColor = .black
        view.placeHolderColor = UIColor.color(hexString: "#999999",alpha: 1)
        view.placeHolder = "Write down your pet story…"
        view.returnKeyType = .done
        view.font = .setTypeFace(16.Fit,type: .medium)
        return view
    }()
    private lazy var doneButton: UIButton = {
        let button = UIButton(type: .custom)
        button.titleLabel?.font = .setTypeFace(22.Fit,type: .extraBold)
        button.setTitleColor(mainColor, for: .normal)
        button.setTitle("Post", for: .normal)
        button.backgroundColor = .black
        button.layer.cornerRadius = 25
        return button
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        view.subviews {
            titL
            descView
            doneButton
        }
        titL.left(35.Fit).top(NavHeight + 22.Fit).right(35.Fit).height(70.Fit)
        titL.textAlignment = .center
        titL.numberOfLines = 0
        
        descView.left(15.Fit).right(15.Fit).height(350.Fit)
        descView.Top == titL.Bottom + 15.Fit
        descView.setAllCorners(corner: 20.Fit)
        descView.backgroundColor = .white

        doneButton.left(30.Fit).right(30.Fit).height(50).bottom(TabbarSafeBottomMargin + 5.Fit)
        doneButton.addAct {
            Toast_View_Tool.show()
            
            guard self.descView.text.isBlank == false else {
                Toast_View_Tool.show(type: .error,text: "The description cannot be empty.")
                return
            }
            Toast_View_Tool.show()
            let date = Date()
            let timeFormatter = DateFormatter()
            timeFormatter.dateFormat = "MM-dd HH:mm"
            let strNowTime = timeFormatter.string(from: date) as String
            var dict:[String:Any] = [:]
            dict["userId"] = USEINFOMODEL.id
            dict["icon"] = USEINFOMODEL.headImage
            dict["info"] = USEINFOMODEL.name
            dict["info0"] = self.descView.text ?? ""
            dict["info3"] = "1"
            dict["info4"] = strNowTime
            dict["password"] = "0"
            RT.createHouse(paraInfo: dict) { s in
                Toast_View_Tool.show(type: .success,text: "Success")
                self.navigationController?.popViewController(animated: true)
            }
        }

    }

}
